package com.ctshk.sapp.hotel.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.utils.individual.conversion.BatchStrategyReq;
import com.ctshk.common.utils.individual.conversion.dto.BatchStrategyDto;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.hotel.dto.HotelProductDetailDTO;
import com.ctshk.rpc.hotel.dto.HotelProductListDTO;
import com.ctshk.rpc.hotel.dto.HotelProductManagePageDTO;
import com.ctshk.rpc.hotel.dto.HotelProductStrategyDTO;
import com.ctshk.rpc.hotel.req.*;
import com.ctshk.rpc.hotel.service.IHotelProductStrategyService;
import com.ctshk.sapp.hotel.convertor.Convertor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 酒店产品加幅策略 前端控制器
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-03
 */
@RestController
@Api(value = "酒店产品加幅策略", tags = "酒店产品加幅策略")
@RequestMapping("/hotel/product/strategy")
public class HotelProductStrategyController extends BaseController {
    @DubboReference
    private IHotelProductStrategyService hotelProductStrategyService;

    @ApiOperation(value = "产品中心-酒店票管理列表查询", notes = "产品中心-酒店票管理列表查询")
    @PostMapping(value = "/queryList")
    public Result<PageResponse<HotelProductListDTO>> queryList(@RequestBody @Valid HotelListProductReq hotelProductPageReq) {
        return Result.success(hotelProductStrategyService.queryList(hotelProductPageReq));
    }

    @ApiOperation(value = "酒店产品上架加幅设置-保存加幅策略", notes = "酒店产品上架加幅设置-保存加幅策略")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "酒店产品上架加幅设置-保存加幅策略", operDesc = "酒店产品上架加幅设置-保存加幅策略")
    @PostMapping("/save")
    public Result save(@RequestParam("hotelProductId") Long hotelProductId, @Valid @RequestBody List<HotelProductStrategyReq> hotelProductStrategyReqList) {
        Long userId = getCurrentUser(getRequest()).getId();
        return hotelProductStrategyService.save(hotelProductId, hotelProductStrategyReqList, userId);
    }


    @ApiOperation(value = "酒店加幅策略-批量保存加幅策略", notes = "酒店加幅策略-批量保存加幅策略")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "酒店加幅策略-批量保存加幅策略", operDesc = "酒店加幅策略-批量保存加幅策略")
    @PostMapping("/save/batch")
    public Result saveBatch(@RequestBody @Valid BatchStrategyReq batchStrategyReq) {
        Long userId = getCurrentUser(getRequest()).getId();
        HotelProductStrategySaveBatchReq hotelProductStrategySaveBatchReq = Convertor.frontToHotelProduct(batchStrategyReq);
        return hotelProductStrategyService.saveBatch(hotelProductStrategySaveBatchReq, userId);
    }


    @ApiOperation(value="根据产品id查询产品加幅详情信息", notes="根据产品id查询产品加幅详情信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据产品id查询产品加幅详情信息", operDesc = "根据产品id查询产品加幅详情信息")
    @GetMapping("/queryByProductId")
    public Result<BatchStrategyDto> queryByProductId(@RequestParam(value = "productId", required = true) Long productId) {
        List<HotelProductStrategyDTO>  list = hotelProductStrategyService.queryByProductId(productId);
        return Result.success(Convertor.hotelProductToFront(list));
    }

    @ApiOperation(value = "酒店-产品中心-查看详情", notes = "酒店-产品中心-查看详情)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "酒店-产品中心-查看详情", operDesc = "酒店-产品中心-查看详情")
    @PostMapping("/detail")
    public Result<HotelProductDetailDTO> getDetail(@RequestBody @Valid HotelProductStrategysDateReq hotelProductStrategysDateReq) {
        return hotelProductStrategyService.selectDetail(hotelProductStrategysDateReq);
    }
}
